package c1761;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(); // n是总题数，m是罚时数
        ArrayList<Student> list = new ArrayList<>();
        while (sc.hasNext()) {
            String name = sc.next();
            int ac = 0;
            int time = 0;
            for (int i = 0; i < n; i++) {
                String s = sc.next();
                if (s.charAt(0) == '-' || s.charAt(0) == 0) continue;
                if (s.charAt(0) > '0' && s.charAt(0) <= '9') {
                    ac++;
                    if (s.indexOf('(') < 0) { // 一次过
                        time += Integer.parseInt(s);
                    } else {
                        String s1 = s.substring(0, s.indexOf('('));
                        time += Integer.parseInt(s1);
                        String s2 = s.substring(s.indexOf('(') + 1, s.indexOf(')'));
                        time += m * Integer.parseInt(s2);
                    }
                }
            }
            list.add(new Student(name, ac, time));
        }
        Collections.sort(list);
        for (Student s : list) {
            System.out.printf("%-10s%3d%5d\n", s.name, s.ac, s.time);
        }
        sc.close();
    }

    static class Student implements Comparable<Student> {
        String name;
        int ac;
        int time;

        public Student(String name, int ac, int time) {
            this.name = name;
            this.ac = ac;
            this.time = time;
        }

        @Override
        public int compareTo(Student that) {
            if (this.ac != that.ac) return that.ac - this.ac;
            if (this.time != that.time) return this.time - that.time;
            return this.name.compareTo(that.name);
        }
    }
}